home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Fades ƒ / Pour scroll fade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-11  |  2.9 KB  |  115 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Pour scroll fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define CorrectTime 2
  32. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  33. #define theWindowWidth (boundsRect.right-boundsRect.left)
  34.  
  35. pascal short PourScrollFade(Rect boundsRect, Pattern *thePattern);
  36.  
  37. /* Scroll down in tiny strips, starting at the left and moving right.  Scroll
  38.    strips 1-(N), then strips 1-(N+1), etc.  When strip 1 is done, don't do it
  39.    anymore!  (Duh, but this was difficult to get right.)  So only scroll strips
  40.    2-(N), and so on. */
  41.    
  42. pascal short PourScrollFade(Rect boundsRect, Pattern *thePattern)
  43. {
  44.     Rect            *dest;
  45.     int                *iter;
  46.     Rect            scrollsource;
  47.     int                i;
  48.     int                startstrip,endstrip;
  49.     int                ScrollSize, BoxSize;
  50.     long            temp;
  51.     int                NumStrips;
  52.     
  53.     NumStrips=theWindowWidth/4;
  54.     dest=(Rect*)NewPtr(sizeof(Rect)*NumStrips);
  55.     if (dest==0L)
  56.         return -1;        /* memory error */
  57.     iter=(int*)NewPtr(sizeof(int)*NumStrips);
  58.     if (iter==0L)
  59.     {
  60.         DisposePtr(dest);
  61.         return -1;        /* memory error */
  62.     }
  63.     
  64.     ScrollSize=theWindowHeight/50;
  65.     BoxSize=theWindowWidth/NumStrips;
  66.     
  67.     SetRect(&scrollsource, boundsRect.left, boundsRect.top, boundsRect.left+BoxSize,
  68.         boundsRect.bottom);
  69.         
  70.     for (i=0; i<NumStrips; i++)
  71.     {
  72.         dest[i].top = 0;
  73.         dest[i].bottom=ScrollSize;
  74.         dest[i].left=i*BoxSize;
  75.         dest[i].right=dest[i].left+BoxSize;
  76.         OffsetRect(&(dest[i]), boundsRect.left, boundsRect.top);
  77.         
  78.         iter[i]=theWindowHeight;
  79.     }
  80.     
  81.     startstrip=0;
  82.     endstrip=1;
  83.     do
  84.     {
  85.         StartTiming();
  86.         
  87.         ScrollRect(&scrollsource, 0, ScrollSize, 0L);
  88.         
  89.         for (i=startstrip; i<endstrip; i++)
  90.         {
  91.             FillRect(&dest[i], *thePattern);
  92.             iter[i]-=ScrollSize;
  93.         }
  94.         
  95.         if (endstrip<NumStrips)
  96.         {
  97.             endstrip++;
  98.             scrollsource.right+=BoxSize;
  99.         }
  100.         if (iter[startstrip]<=0)
  101.         {
  102.             startstrip++;
  103.             scrollsource.left+=BoxSize;
  104.         }
  105.         
  106.         TimeCorrection(CorrectTime);
  107.     }
  108.     while (startstrip<endstrip);
  109.     
  110.     DisposePtr(dest);
  111.     DisposePtr(iter);
  112.     
  113.     return 0;
  114. }
  115.